import { UserProfilesAPI } from "@/request/api";
export default {
  namespaced: true,

  //数据
  state: {
    //用户信息
    userInfo: {
      nickName: "昵称",
      coin: 5,
      headImg: require("../../assets/img/userImg.f8bbec5e.png"),
    },
    //购物车数量
    cartTotal: 99,
  },

  mutations: {
    //修改显示隐藏的方法
    chengeUserInfo(state, payload) {
      state.userInfo = payload.userInfo;
      state.cartTotal = payload.cartTotal;
    },

    //初始化用户信息
    initUserInfo(state, payload) {
      (state.userInfo = {
        nickName: "昵称",
        coin: 5,
        headImg: require("../../assets/img/userImg.f8bbec5e.png"),
      }),
        (state.cartTotal = 99);
    },
  },
  actions: {
    async asyncChengeUserInfo({ commit }, payload) {
      let user = await UserProfilesAPI();
      console.log("actions-user", user);
      commit("chengeUserInfo", user.data);
    },
  },
};
